package com.ms.education.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>Project:我的代码-RedissonConfig
 * <p>Powered by ms on 2023-02-09 22:52:35
 *
 * @author ms
 * @version 1.0
 * @since 1.8
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private String redisPort;

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer().setAddress("redis://"+redisHost+":"+redisPort)
                .setDatabase(0)
                .setConnectionMinimumIdleSize(10)//连接池的最小连接数
                .setConnectionPoolSize(50)//连接池最大连接数
                .setIdleConnectionTimeout(60000)//除了核心线程外，空闲线程的超时时间
                .setConnectTimeout(100000)//客户端获取redis连接的超时时间
                .setTimeout(100000);//响应超时时间
        return Redisson.create(config);
    }
}
